package com.hgh.util;

import com.hgh.model.EnemyTank;
import com.hgh.model.Map;
import com.misakubex.BTFrame;

import java.util.List;
import java.util.concurrent.TimeUnit;

public class GenerateEnemyTank implements Runnable {

    private int index;
    /**
     *
     * @param index,出生地点的序号
     */
    public GenerateEnemyTank(int index){
        this.index = index;
    }

    public static List<EnemyTank> getEnemyTankList(int index){
        switch (index){
            case 1:return BTFrame.enemyTankList1;
            case 2:return BTFrame.enemyTankList2;
            case 3:return BTFrame.enemyTankList3;
            default:return null;
        }
    }

    @Override
    public void run() {
        while (true){
            if (getEnemyTankList(index).size() < 2) {
                EnemyTank enemyTank = new EnemyTank();
                enemyTank.setX(Map.enemyTankBornPoint[index-1][0]);
                enemyTank.setY(Map.enemyTankBornPoint[index-1][1]);
                enemyTank.setTargetPoint(Map.base);
                enemyTank.setBornMark(index);
                enemyTank.setDirct('w');
                BTFrame.threadPoolExecutor.execute(new EnemyTankLocal(enemyTank));
                getEnemyTankList(index).add(enemyTank);
                EnemyTankMoveAstar enemyTankMoveAstar = new EnemyTankMoveAstar(enemyTank);
                BTFrame.threadPoolExecutor.execute(enemyTankMoveAstar);
            }
            try {
                TimeUnit.MILLISECONDS.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
